package interaction.input.concrete;

import java.util.LinkedList;
import java.util.List;

import processing.core.PVector;

import interaction.input.DataComponent;
import interaction.sampling.Sample;
import interaction.sampling.SampleSet;

public abstract class AbstractSignatureComponent extends DataComponent<SampleSet> {
	private int beatsToCollect;
	private List<Sample> beats = new LinkedList<Sample>();
	
	public AbstractSignatureComponent(PVector position, PVector size, int beatsToCollect) {
		super(position, size);
		this.beatsToCollect = beatsToCollect;
	}
	
	public List<Sample> getBeats() {
		return beats;
	}
	
	public void beatReceived(Sample s) {
		if (beats.size() < beatsToCollect) {
			beats.add(s);
			
			if (beats.size() == beatsToCollect) {
				getDataSource().set(new SampleSet(beats));
			}
		}
	}
}
